import { _decorator, Color, Component, instantiate, Label, Node, Prefab, ScrollView, Sprite } from 'cc';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';

import { UIHeader } from '../common/UIHeader';
import { EventManager } from '../event/EventManager';
import { TabLayout } from '../common/TabLayout';
import ResManager from '../common/ResManager';
const { ccclass, property } = _decorator;

@ccclass('ReportIndex')
export class ReportIndex extends Component {
    @property(UIHeader)
    uiHeader:UIHeader
    @property(TabLayout)
    tabLayout:TabLayout
    @property(Node)
    content:Node
 
    start() {
        console.log('ReportIndex start...')
        this.uiHeader.setData('邮件')
        EventManager.instance.on('邮件close', this.onClose, this)

        this.tabLayout.setData(['报告','系统消息'])
        EventManager.instance.on('报告', this.onReport, this )
        EventManager.instance.on('系统消息', this.onMessage, this )

        this.onReport()
    }

    onClose(){
        UIManager.instance.closeUI(PrefabEnum.ReportIndex)
    }
    
    async onReport(){
        this.content.destroyAllChildren()
        let prefab = await ResManager.instance.loadAssetByUrl<Prefab>(PrefabEnum.ReportList)
        let node = instantiate(prefab)
        this.content.addChild(node)
    }

    async onMessage(){
        this.content.destroyAllChildren()
        let prefab = await ResManager.instance.loadAssetByUrl<Prefab>(PrefabEnum.MessageList)
        let node = instantiate(prefab)
        this.content.addChild(node)
    }

}


